package com.example.leetdemo.consistenthash;

import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

public class TestConsumption {

    private SortedMap<String, Integer> sortedMap = new TreeMap();


    public void initSortMap() {
        sortedMap.put("05:00", 1);
        sortedMap.put("08:00", 2);
        sortedMap.put("10:00", 3);
        sortedMap.put("12:00", 1);
        sortedMap.put("16:00", 2);
        sortedMap.put("19:00", 1);
        sortedMap.put("20:00", 4);
        sortedMap.put("23:00", 2);
    }

    public Integer getNowConsumption(String time) {
        Integer consumption = 0;
        SortedMap<String, Integer> thisSort = sortedMap.headMap(time);
        if (thisSort.size() == 0) {
            consumption = sortedMap.get(sortedMap.lastKey());
        } else {
            consumption = sortedMap.get(thisSort.lastKey());
        }
        return consumption;
    }

    public static void main(String[] args) {
//        TestConsumption testConsumption = new TestConsumption();
//        testConsumption.initSortMap();
//        System.err.println(testConsumption.getNowConsumption("04:31"));

//        System.err.println((int) (Math.random() * 5));
        StringBuilder stringBuilder = new StringBuilder();
        StringBuffer stringBuffer = new StringBuffer();
        System.err.println();
    }
}
